package archer.framework.security.utils;

import archer.framework.security.netpolice.SuspiciousEvent;
import archer.framework.security.netpolice.NetPolice;
import archer.framework.utils.ContextUtils;
import archer.framework.utils.ValidateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 可疑事件工具类
 *
 * @author christ
 * @date 2016/8/18
 */
public class SuspiciousUtils {

    private static final Logger logger = LoggerFactory.getLogger(SuspiciousUtils.class);

    /**
     * 上报可疑事件
     *
     * @param suspicious
     */
    public static void report(SuspiciousEvent suspicious) {

        NetPolice police = null;
        try {
            police = ContextUtils.getBean(NetPolice.class);
        } catch (Exception e) {
            // 问题不大
            logger.warn("没找到NetPolice的实现类", e);
        }

        if (ValidateUtils.isNotEmpty(police)) {
            police.report(suspicious);
        }
    }
}
